﻿using LJ.Abstractions.Extensions;
using LJ.Abstractions.Pack.Attributes;
using LJ.Host.Abstractions.Exceptions;
using LJ.Host.Abstractions.Pack;
using LJ.Host.Worker.Pack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJ.Host.Worker.Extensions;

public static class ServiceProviderExtensions
{
    public static IServiceProvider UseLJ(this IServiceProvider  serviceProvider)
    {

        var packProvider = new PackProvider(serviceProvider);

        var packManager = serviceProvider.GetRequiredService<IPackManager>();

        packProvider.Logger.LogInformation("---------------------");
        packProvider.Logger.LogInformation("Load LJ");

        foreach (var pack in packManager.GetPacks())
        {
            var packType = pack.GetType();
            //var packAttributes = packType.GetAttributes<PackAttribute>();

            //if (packAttributes.Where(a => a.PackType == PackType.Web).Any())
            //{
            //    throw new PackException($"加载模块{packType.FullName}时无法找到依赖模块");
            //}
        }
        packProvider.Logger.LogInformation("Load Pack Ok");
        packProvider.Logger.LogInformation("---------------------");

        return serviceProvider;
    }
}

